"""
公共功能
"""


# 登录认证装饰器
def auth(role):
    from core import admin, teacher, student
    def login_auth(func):
        def inner(*args, **kwargs):
            if role == 'admin':
                if admin.admin_info.get('user'):
                    res = func(*args, **kwargs)
                    return res
                else:
                    print('未登录，无法享受特殊服务~~~')
                    admin.login()

            elif role == 'teacher':
                if teacher.teacher_info.get('user'):
                    res = func(*args, **kwargs)
                    return res
                else:
                    print('未登录，无法享受特殊服务~~~')
                    teacher.login()

            elif role == 'student':
                if student.student_info.get('user'):
                    res = func(*args, **kwargs)
                    return res
                else:
                    print('未登录，无法享受特殊服务~~~')
                    student.login()

        return inner
    return login_auth
